package com.ruoyi.system.controller;

import java.util.ArrayList;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.OaCandidateInfo;
import com.ruoyi.common.core.domain.OaResult;
import com.ruoyi.common.core.utils.facade.OaBusinessFacade;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.system.service.IOaCandidateInfoService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 候选人信息Controller
 * 
 * @author ruoyi
 * @date 2020-12-29
 */
@RestController
@RequestMapping("/info")
public class OaCandidateInfoController extends BaseController
{
    @Autowired
    private IOaCandidateInfoService oaCandidateInfoService;

    /**
     * 查询候选人信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(OaCandidateInfo oaCandidateInfo)
    {
        startPage();
        List<OaCandidateInfo> list = oaCandidateInfoService.selectOaCandidateInfoList(oaCandidateInfo);
        return getDataTable(list);
    }

    /**
     * 导出候选人信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "候选人信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OaCandidateInfo oaCandidateInfo) throws IOException
    {
        List<OaCandidateInfo> list = oaCandidateInfoService.selectOaCandidateInfoList(oaCandidateInfo);
        ExcelUtil<OaCandidateInfo> util = new ExcelUtil<OaCandidateInfo>(OaCandidateInfo.class);
        util.exportExcel(response, list, "info");
    }

    /**
     * 获取候选人信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(oaCandidateInfoService.selectOaCandidateInfoById(id));
    }

    /**
     * 新增候选人信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "候选人信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OaCandidateInfo oaCandidateInfo)
    {
        List<OaCandidateInfo> list=new ArrayList<>();
        list.add(oaCandidateInfo);
        OaResult result=  OaBusinessFacade.addCandidateInfo(list);
        if("200".equals(result.getCode())){
            oaCandidateInfo.setCode("200");
            oaCandidateInfo.setMessage(result.getMessage());
            return toAjax(oaCandidateInfoService.insertOaCandidateInfo(oaCandidateInfo));
        }else if("400".equals(result.getCode())){
            return AjaxResult.success("该招聘需求已关闭");
        }
        return toAjax(0);
    }

    /**
     * 修改候选人信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "候选人信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OaCandidateInfo oaCandidateInfo)
    {
        return toAjax(oaCandidateInfoService.updateOaCandidateInfo(oaCandidateInfo));
    }

    /**
     * 删除候选人信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "候选人信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(oaCandidateInfoService.deleteOaCandidateInfoByIds(ids));
    }
}
